package com.axsoft.jobimp;

import com.axsoft.jobimp.types.BLK;
import com.axsoft.jobimp.types.sTLD;
import com.axsoft.jobimp.types.wTLD;


/**
 * 
 * @author RankoR
 * 
 * Implement BEX packet parser and storage
 * 
 *  BEX Structure:
 *  * BEX Header (17 bytes)
 *  * Data (sTLD or wTLD) (4 or 8 + variable bytes)
 * 
 */
public class BEX {
	
	private OHeader mHeader;
	private final sTLD mSTld;
	private wTLD mWTld;
	
	public final OHeader getHeader() {
		return mHeader;
	}
	
	public final sTLD getSTld() {
		return mSTld;
	}
	
	public final wTLD getWTld() {
		return mWTld;
	}
	
	public BEX() {
		mHeader = new OHeader();
		mSTld = new sTLD();
		mWTld = new wTLD();
	}
	
	
	public BEX(final BLK pBLK, boolean pShort) {
		parseBLK(pBLK, pShort);
	}
	
	/**
	 * Parses BLK. 
	 * pShort shows if BLK contains sTLD or wTLD
	 */
	public void parseBLK(final BLK pBLK, final boolean pShort) {
		if (pBLK == null) {
			return;
		}
		
		mHeader = new OHeader(pBLK.copyBytes(0, OHeader.HEADER_LENGTH));
		final BLK blk = pBLK.copyBytes(OHeader.DATA_OFFSET, mHeader.mLength.getValue());
		
		if (pShort) {
			mSTld = new sTLD(blk);
		}
	}
	
}
